// 7-3 通讯录排序
#include <stdio.h>

struct Info {
    char name[11];
    int date; // yyyymmdd, 似乎可以直接比大小
    char phone[20];
};

int main()
{
    int n;
    scanf("%d", &n);
    struct Info friends[n];
    for (int i=0; i<n; i++) {
        scanf("%s%d%s", friends[i].name, &friends[i].date, friends[i].phone);
    }
    for (int i=0; i<n-1; i++) {
        int min = i;
        for (int j=i+1; j<n; j++) {
            if (friends[min].date > friends[j].date) {
                min = j;
            }
        }
        struct Info t = friends[min];
        friends[min] = friends[i];
        friends[i] = t;
    }
    for (int i=0; i<n; i++) {
        printf("%s %d %s\n", friends[i].name, friends[i].date, friends[i].phone);
    }
    return 0;
}